package com.gym.controller;


import com.gym.service.CaptchaService;
import com.gym.utils.service.JSONResult;
import com.gym.utils.service.RedisOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 *
 * @author gym
 * @since 2024-02-13
 */


@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {


    @Autowired
    CaptchaService captchaService;
    @Autowired
    RedisOperator redisOperator;

    @GetMapping("send")
    public JSONResult send(String phone, HttpServletRequest request)  {
        /*boolean isValid = PhoneUtil.isMobile(phone);
        if(!isValid){
            return  JSONResult.errorMsg("手机号格式不正确" );
        }
        // 获得用户ip
        String userIp = IPUtil.getRequestIp(request);
        log.info("send,phone:{},ip:{}",phone,userIp);
        boolean ipExist = redisOperator.keyIsExist("MOBILE_SMSCODE" + ":" + userIp);

        if (ipExist) {

            return JSONResult.errorMsg("短信发送频率太高了~~！！！" );
        }
        // 限制用户只能在60s以内获得一次验证码
        redisOperator.setnx60s("MOBILE_SMSCODE" + ":" + userIp, phone);

        return captchaService.secondValidateCaptcha(phone, String.valueOf(RandomUtil.randomInt(1000, 10000)));*/
        return JSONResult.errorMsg("短信发送频率太高了~~！！！" );
    }







}

